package app.blog.entity;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import slap.berkeleydb.BDB;

import app.blog.Blog;

import com.sleepycat.persist.PrimaryIndex;
import com.sleepycat.persist.SecondaryIndex;
import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.PrimaryKey;
import com.sleepycat.persist.model.Relationship;
import com.sleepycat.persist.model.SecondaryKey;


@Entity
public class Page extends Post{
	
	protected static PrimaryIndex<Integer, Page> primaryIndex = 
		BDB.instanse(Blog.bdbName).getEntityStore().getPrimaryIndex(Integer.class, Page.class);
	
	protected static SecondaryIndex<String, Integer, Page> indexOnName = 
		BDB.instanse(Blog.bdbName).getEntityStore().getSecondaryIndex(primaryIndex, String.class, "name");
	
	protected static SecondaryIndex<Date, Integer, Page> indexOnPupDate = 
		BDB.instanse(Blog.bdbName).getEntityStore().getSecondaryIndex(primaryIndex, Date.class, "pubDate");
	
	
	public static void persist(Page post){
		primaryIndex.putNoReturn(post);
	}
	
	public static Page getById(Integer id){
		return primaryIndex.get(id);
	}
	
	public static Page getByName(String name) {
		return indexOnName.get(name);
	}
	
	public static List<Page> all() {
		List<Page> all;
		all = BDB.asList(primaryIndex);
		return all;
	}
	
	public String template;

}
